﻿@{
    ViewBag.Title = "用户管理";
    Layout = "~/Views/Shared/_LayoutList.cshtml";

    var grid = Html.DWZGridFor<UserInfo>()
        .ID("grdList")
        .Action(@Url.Action("OrgUserList"))
        .Width("mainWidth")
        .ExtParam(new { ParentId = "$('#ParentId').val()" })
        .Columns(col =>
        {
            col.Bind(e => e.Id).IsKey();
            col.Bind(e => e.UserCode).Width(80).AsQuery().Align(FlexiGridAlign.Left);
            col.Bind(e => e.UserName).Width(100).AsQuery().Align(FlexiGridAlign.Left);
            col.Bind(e => e.AccountState).EnumKey("AccountState").Width(60);
            col.Bind(e => e.SeqNo).Width(40);
            col.Bind(e => e.UpdateUser).Width(60);
            col.Bind(e => e.UpdateDate).Width(70).DateFormat("yyyy-MM-dd");
            col.Bind(e => e.Id, "操作", 120).Sortable(false)
                .Template(Url.EditLink("EditUser", "编辑用户")
                + Url.DeleteLink("DeleteUserInfo", "${UserName}"));
        })
        .Buttons(btn =>
        {
            btn.Bind("Add", "新建用户", FlexiGridButtonType.Add).OnPress("AddUser");
            btn.Bind("Add", "导入用户", FlexiGridButtonType.Add).OnPress("ExportData");
        });
}
@Html.Css("tree")
@Html.Js("tree")
<script type="text/javascript">
    var maiheight = document.documentElement.clientHeight;
    var mainWidth = document.documentElement.clientWidth - 3 - 170; // 减去边框和左边的宽度
    var otherpm = 82;
    var gh = maiheight - otherpm;
    $(document).ready(function () {
        // 部门树控件
        $("#Tree").treeview({
            url: '@Url.Action("OrgInfoTreeList")',
            showcheck: false,
            onnodeclick: TreeNode_Click,
            theme: "bbit-tree-no-lines" //bbit-tree-lines ,bbit-tree-no-lines,bbit-tree-arrows
        }).height(maiheight - 30);
        function TreeNode_Click(data) {
            // 刷新右边的列表，并保存当前节点的值
            $("#grdList").flexOptions({ extParam: [{ name: "parentId", value: data.value}] }).flexReload();
            $("#ParentId").val(data.value);
            $("#ListTitle").text(data.text);
        } 
    });

    // 添加部门信息
    function AddUser(id) {
        var url = "@Url.Action("EditUser")?ParentId=" + $('#ParentId').val();
        OpenModelWindow(url,{ width: 470, height: 330, caption: "添加用户信息", onclose:refreshGrid});
        return false;
    }

    function ExportData(id)
    {
        var url = 'http://'+window.location.hostname+':1590/ExcelImportXml.aspx?Id=D48459C5-C787-41C6-9DD3-0CD9F129860A';
        OpenModelWindow(url,{ width: 870, height: 630, caption: "导入用户信息", onclose:refreshGrid});
        return false;
    }

    // 重载刷新列表Grid
    function refreshGrid() {
        // 刷新列表
        showLoadingMsg("操作成功", { left: 300, top: 2 }, true, 3000);
        $("table.flexigrid").flexReload();

        // 同步刷新树
        //$("#grdUserList").refresh($('#ParentId').val());
    }
</script>
<div class="MainContainer" style="overflow: hidden;">
    <table width="100%" cellpadding="0" cellspacing="0" class="tree_grid_panel_table">
        <tbody>
            <tr>
                <td style="width: 170px;">
                    <div class="header">
                        <span class="title">组织机构树</span></div>
                    <div id="Tree" class="treeview">
                    </div>
                </td>
                <td style="width: 2px;">
                </td>
                <td>
                    <div class="header">
                        <span id="ListTitle" class="title">所有用户</span></div>
                    @Html.Raw(grid.ToString())
                </td>
            </tr>
        </tbody>
    </table>
    @Html.Hidden("ParentId")
</div>
